package com.zahb.qadx.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zahb.qadx.R;
import com.zahb.qadx.model.Mission24;
import com.zahb.qadx.util.ImageLoaderKt;
import com.zhpan.bannerview.BaseBannerAdapter;
import com.zhpan.bannerview.BaseViewHolder;

public class ByLanguageDialogAdapter extends BaseBannerAdapter<Mission24.SafetySloganListBean, ByLanguageDialogAdapter.BannerViewHolder> {

    public static Context mContexts;
    @Override
    protected void onBind(ByLanguageDialogAdapter.BannerViewHolder holder, Mission24.SafetySloganListBean data, int position, int pageSize) {
        holder.bindData(data, position, pageSize);
    }

    public ByLanguageDialogAdapter(Context mContext) {
        this.mContexts = mContext;
    }
    @Override
    public ByLanguageDialogAdapter.BannerViewHolder createViewHolder(@NonNull ViewGroup parent, View itemView, int viewType) {
        return new ByLanguageDialogAdapter.BannerViewHolder(itemView);

    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_bylanguage_window_view;
    }

    public static class BannerViewHolder extends BaseViewHolder<Mission24.SafetySloganListBean> {
        boolean isCompletedDraw = false;
        BannerViewHolder(@NonNull View itemView) {
            super(itemView);

        }

        @Override
        public void bindData(Mission24.SafetySloganListBean data, int position, int pageSize) {
            TextView tvRead = findView(R.id.tvRead);//侧量宽度

            TextView mTextView = findView(R.id.enterprise_slogan);
            tvRead.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (!isCompletedDraw){
                        isCompletedDraw = true;
                        // h就是TextView的高度,h就是TextView的宽度
                        int h = tvRead.getMeasuredHeight();
                        int w = tvRead.getMeasuredWidth();
                        //为ImageView设置宽高
                        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mTextView.getLayoutParams();
                        params.width = w;
                        mTextView.setLayoutParams(params);
                    }
                    Log.e("走了这里","几次");
                }
            });
            ImageView imageView = findView(R.id.iv_banner);


            TextView celebrity = findView(R.id.celebrity);
            mTextView.setText(data.getSlogan());
            celebrity.setText(data.getSign());
            ImageLoaderKt.loadImage(imageView, data.getImgUrl());





        }
    }
}
